// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import './assets/css/index.css'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
// axios
import axios from 'axios'
// 1. 路由
import router from '@/router/'
Vue.config.productionTip = false
// 2.ElementUI
Vue.use(ElementUI)

// 3.axios基本配置
Vue.prototype.axios = axios
// 基础路径配置
axios.defaults.baseURL = 'http://localhost:8888/api/private/v1/'
// 拦截器
axios.interceptors.request.use(config => {
  config.headers.Authorization = localStorage.getItem('token')
  return config
})
axios.interceptors.response.use(res => {
  if (res.data.meta.status === 403) {
    vm.$message({
      type: 'error',
      message: res.data.meta.msg
    })
    vm.$router.push('/home')
    return
  }
  return res
})
/* eslint-disable no-new */
const vm = new Vue({
  el: '#app',
  components: { App },
  template: '<App/>',
  router
  // render (c) {
  //   return c(App)
  // }
})
